#ifndef CLASSMETHOD_H
#define CLASSMETHOD_H

#include <QList>
#include <QListIterator>
#include <QString>
#include <QDebug>
#include <QAbstractTableModel>
#include <QItemDelegate>
#include <QLineEdit>
#include <QDebug>

#include "uml/class/classattribute.h"
#include "gui/editors/methodeditor.h"
#include "gui/editors/visibilitycombobox.h"

class UmlClassItem;

class ClassMethod : public ClassAttribute, public QAbstractTableModel, public QItemDelegate
{
public:
    enum ArgumentMovement {
        MoveUp,
        MoveDown
    };

    ClassMethod(QObject *parent = 0);
    ~ClassMethod();

    bool isAbstract();
    void setIsAbstract(bool isAbstract);

    // adds an argument
    void addAtt(ClassAttribute *att);
    void removeAtt(ClassAttribute *att);
    bool hasArguments();

    void setVisibility(QString visibility);

    QList<ClassAttribute*> argList();

    // Tablemodel
    int rowCount(const QModelIndex &parent) const;
    int columnCount(const QModelIndex &parent) const;
    QVariant headerData(int section, Qt::Orientation orientation, int role) const;
    QVariant data(const QModelIndex & index, int role) const;
    Qt::ItemFlags flags (const QModelIndex & index) const;
    void appendArg(ClassAttribute *att);
    void removeArg(QModelIndex index);
    void moveArg(QModelIndex index, ClassMethod::ArgumentMovement movement);

    // Itemdelegate
    QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const;
    void setEditorData(QWidget *editor, const QModelIndex &index) const;
    void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;

    void openEditor();

private:
    bool _isAbstract;
    QList<ClassAttribute*> _args;
    QList<ClassAttribute*> _argsSave;

protected slots:
    void remove();
    void toggleIsAbstract();
    virtual void updateUmlText();
};

#endif // CLASSMETHOD_H
